-- item_per2floor
-- created by zhuangsl
-- 每前进M层迷宫，获得N个XX

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 进入下层触发触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return 0;
        end

        -- 客户端此时还在前一层，需要+1计算
        local floor = DungeonM.currentLayer() + 1;
        local layer = math.max(1, math.modf(1000 / prop[3]));
        local amount = math.max(1, math.modf(prop[3] / 1000));

        -- 不是在layer倍层，不处理
        if floor % layer ~= 0 then
            return 0;
        end

        -- 奖励
        local id;
        local arr = string.explode(prop[2], "~");
        local rand = DungeonM.getRandSeed("item_per2floor");
        if #arr == 2 then
            if arr[2] <= arr[1] then
                id = tonumber(arr[1]);
            else
                id = tonumber(arr[1]) + rand % tonumber(arr[2] - arr[1] + 1);
            end
        else
            id = tonumber(prop[2]);
        end

        local bonus = {1, id, amount};
        BonusM.doBonus(bonus, "item_per2floor");

        EventMgr.fire(event.LAYER_BONUS_EVENT, { ["bonusList"] = {bonus}, });

        return prop[3];
    end,

    record = function(target, prop, path)
        return false;
    end
};
